/**
 * Server management
 */
var _history = 0;
var alarm = {
	/**
	 * Show server list
	 */
	list : function() {
		var serverlistUrl = baseURL + "/system/alarm/list"
		$.ajax({
			type : "get",
			url : serverlistUrl,
			data:{history : _history},
			dataType : "html",
			success : function(html) {
				// Request successfully and fill the data.
				$("#list").empty().html(html);
			}
		});
	},
	/**
	 * read alarm
	 */	
	read : function(){
		var alarms = [];
		//将选中数据添加到数组中
		$('input[name="id"]:checked').each(function(){
			alarms.push($(this).val());
		});
		if(alarms==""){
			common.showTip({
				title : localeMsg.common.warn,
				text : localeMsg.common.selectMsg
			});
		}else{
			$.ajax({
				type : "get",
				url : baseURL+"/system/alarm/read",
				data : {
					"alarms" : alarms
				},
				dataType : "json",
				traditional : true,
				success : function(json){
					if(json.result && json.result == "success"){
						common.showTip({
							title : localeMsg.common.prompt,
							text : localeMsg.alarm.readSuccess,
							success: true,
							callback : function(){
								alarm.list();
								var count = json["alarm"];
								if(count == 0 ){
									$("#portal_div_header").hide();
								}
								else{
									$("#portal_div_header_span").text(count);
									$("#portal_div_header").show();
								}
							}
						});
					}else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.deleteFail,
							success: false
						});
					}
				}
			});
		}
	},
	
	screen : function() {
		var hostname = $("#node").val();
		var type = $("#type").val();
		var importance = $("#importance").val();
		var history = $("#history").val();
		_history = history;
//		if(type==localeMsg.alarm.mem){
//			var type=1;
//		}else if(type==localeMsg.alarm.cpu){
//			var type=0;
//		}else if(type==localeMsg.alarm.dir){
//			var type=2;
//		}else if(type==localeMsg.alarm.global){
//			var type=3;
//		}else if(type==localeMsg.alarm.pool){
//			var type=4;
//		}else if(type==localeMsg.alarm.osdperf){
//			var type=5;
//		}else if(type==localeMsg.alarm.osdstatus){
//			var type=6;
//		}else if(type==localeMsg.alarm.cluster){
//			var type=7;
//		}
		var begintime = $("#begintime").datebox('getValue');	
		var endtime = $("#endtime").datebox('getValue');
		$('#nodeForPager').attr({value : hostname});
		$('#typeForPager').attr({value : type});
		$('#begintimeForPager').attr({value : begintime});
		$('#endtimeForPager').attr({value : endtime});
		$('#importanceForPager').attr({value : importance});
		$('#historyForPager').attr({value : history});
		$.ajax({
			type : "post",
			url : baseURL + "/system/alarm/screen",
			dataType : "html",
			data : {
				hostname : hostname,
				//ip : ip,
				type : type,
				begintime : begintime,
				endtime : endtime,
				importance : importance,
				history : history
			},
			success : function(html) {
				// Request successfully and fill the data.
				$("#list").empty().html(html);
			}
		});
	},
	
	remove : function(){
		var alarms = [];
		//将选中数据添加到数组中
		$('input[name="id"]:checked').each(function(){
			alarms.push($(this).val());
		});
		if(alarms==""){
			common.showTip({
				title : localeMsg.common.warn,
				text : localeMsg.common.selectMsg
			});
		}else{
			$.ajax({
				type : "get",
				url : baseURL+"/system/alarm/remove",
				data : {
					"alarms" : alarms
				},
				dataType : "json",
				traditional : true,
				success : function(json){
					if(json.result && json.result == "success"){
						common.showTip({
							title : localeMsg.common.prompt,
							text : localeMsg.common.deleteSuccess,
							success: true,
							callback : function(){
								alarm.list();
							}
						});
					}else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.deleteFail,
							success: false
						});
					}
				}
			});
		}
	}
	
};